package net2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpEasyServer {

    private static final int PORT = 4090;
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(PORT);
        System.out.println("服务器已开启...");
        while (true) {
            System.out.println("等待与客户端建立连接...");
            Socket client = socket.accept();
            System.out.println("成功与客户端：" +
                    client.getInetAddress() +
                    " /" +
                    client.getPort() +
                    "建立连接");
            InputStream is = client.getInputStream();
            BufferedReader bf = new BufferedReader(
                    new InputStreamReader(is, "UTF-8"));
            String line;
            while ((line = bf.readLine()) != null) {
                System.out.println(line);
            }
            client.close();
        }
    }

}